package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.business.entity.Certification;
import cn.stylefeng.guns.modular.business.model.params.CertificationParam;
import cn.stylefeng.guns.modular.business.model.result.CertificationResult;
import cn.stylefeng.guns.modular.business.service.CertificationService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 实名认证控制器
 *
 * @author pzp
 * @Date 2019-07-25 20:44:04
 */
@Controller
@RequestMapping("/certification")
public class CertificationController extends BaseController {

    private String PREFIX = "/business/certification";

    @Autowired
    private CertificationService certificationService;

    /**
     * 跳转到主页面
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/certification.html";
    }

    /**
     * 新增页面
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/certification_add.html";
    }

    /**
     * 编辑页面
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/edit")
    public String edit(Integer certificationId, Model model) {
        CertificationResult certificationResult = certificationService.findById(certificationId);
        model.addAttribute("certificationResult",certificationResult);
        return PREFIX + "/certification_edit.html";
    }

    /**
     * 新增接口
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CertificationParam certificationParam) {
        this.certificationService.add(certificationParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CertificationParam certificationParam) {
        this.certificationService.update(certificationParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CertificationParam certificationParam) {
        this.certificationService.delete(certificationParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CertificationParam certificationParam) {
        Certification detail = this.certificationService.getById(certificationParam.getCertificationId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(String status, String userName,String modeFlag) {
        return this.certificationService.findPageBySpec(status, userName,modeFlag);
    }


    /**
     * 审批通过
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/approve-success")
    @ResponseBody
    public ResponseData approveSuccess(CertificationParam certificationParam) {
        certificationService.approveSuccess(certificationParam);
        return ResponseData.success();
    }

    /**
     * 审批拒绝
     *
     * @author pzp
     * @Date 2019-07-25
     */
    @RequestMapping("/approve-fail")
    @ResponseBody
    public ResponseData approveFail(CertificationParam certificationParam) {
        this.certificationService.approveFail(certificationParam);
        return ResponseData.success();
    }

}


